﻿using Magicodes.ExporterAndImporter.Excel.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NP.BPMReportPlatform.HSE.Dto;
using NP.BPMReportPlatform.RecurringJobs;
using NP.BPMReportPlatform.Reports.CXYXTHNRA.Dtos;
using NP.BPMReportPlatform.YCLWLJGZSYC.Dto;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace NP.BPMReportPlatform.Reports.CXYXTHNRA
{
    //[Authorize]
    [ApiController]
    [Route("api/Reports/CXYXTHNRA")]
    public class CXYXTHNRAController : BPMReportPlatformController
    {
        private readonly ICXYXTHNRAService _service;
        private readonly ICXYXTHNRRecurringJob _job;
        public CXYXTHNRAController(ICXYXTHNRAService service, ICXYXTHNRRecurringJob job)
        {
            _service = service;
            _job = job;
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("GetAllAsync")]
        public async Task<PagedResultDto<GetCXYXTHNROutput>> GetAllAsync([FromBody] GetCXYXTHNRInput input)
        {
            return await _service.GetAllAsync(input);
        }

        /// <summary>
        /// 导出数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("ExportAsync")]
        public async Task<FileContentResult> ExportData([FromBody] GetCXYXTHNRInput input)
        {
            var data = await _service.ExportAsync(input);
            var ms = new MemoryStream();
            data.Write(ms);
            data.Close();
            return File(ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        }

        /// <summary>
        /// 测试定时任务方法
        /// </summary>
        /// <returns></returns>
        [HttpPost("TestJob")]
        public async Task TestJob()
        {
            await _job.DoJob();
        }
    }
}
